package com.waimai.admin.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.waimai.db.entity.Admin;

public class CheckLoginInterceptor implements HandlerInterceptor {

	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub

	}

	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object obj) throws Exception {
		// TODO Auto-generated method stub
		Admin admin = (Admin) request.getSession().getAttribute("adminLogin");
		System.out.println("url"+request.getRequestURL().toString());
		System.out.println("正在进行admin登陆验证"+admin);
		if (admin == null) {
			// 踢回到登录页面
			response.sendRedirect(request.getContextPath() + "/admin/login");
			return false;
		} else {
			return true;
		}

	}

}
